package com.yunfeisoft.business.model;

import com.yunfeisoft.base.model.WorkflowInstance;
import com.yunfeisoft.common.base.BaseModel;
import com.yunfeisoft.common.sql.record.TransientField;
import com.yunfeisoft.common.utils.DateUtils;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * ClassName: DebitNote
 * Description: 借支单
 *
 * @Author: Jackie liu
 * Date: 2020-04-01
 */
@Entity
@Table(name = "TT_DEBIT_NOTE")
public class DebitNote extends BaseModel implements Serializable {

    /**
     * Field serialVersionUID: 序列号
     */
    private static final long serialVersionUID = 1L;

    /**
     * 流程定义id
     */
    @Column
    private String workflowDefineId;

    /**
     * 申请日期
     */
    @Column
    private Date happenDate;

    /**
     * 还款日期
     */
    @Column
    private Date repayDate;

    /**
     * 支付方式
     */
    @Column
    private Integer payType;

    /**
     * 部门
     */
    @Column
    private String deptName;

    /**
     * 借支事由
     */
    @Column
    private String content;

    /**
     * 借支金额
     */
    @Column
    private BigDecimal amount;

    /**
     * 备注
     */
    @Column
    private String remark;

    /**
     * 状态
     */
    @Column
    private Integer status;

    @TransientField
    private Integer validStatus;
    @TransientField
    private String createName;
    //下一节点处理人
    private String nextStepUserId;

    public String getStatusStr() {
        return DebitNoteStatusEnum.valueOf(status);
    }

    public String getValidStatusStr() {
        return WorkflowInstance.WorkflowInstanceStatusEnum.valueOf(validStatus);
    }

    public String getHappenDateStr() {
        if (happenDate != null) {
            return DateUtils.dateToString(happenDate);
        }
        return null;
    }

    public String getRepayDateStr() {
        if (repayDate != null) {
            return DateUtils.dateToString(repayDate);
        }
        return null;
    }

    public String getPayTypeStr() {
        return PayTypeEnum.valueOf(payType);
    }

    public String getWorkflowDefineId() {
        return workflowDefineId;
    }

    public void setWorkflowDefineId(String workflowDefineId) {
        this.workflowDefineId = workflowDefineId;
    }

    public Date getHappenDate() {
        return happenDate;
    }

    public void setHappenDate(Date happenDate) {
        this.happenDate = happenDate;
    }

    public Date getRepayDate() {
        return repayDate;
    }

    public void setRepayDate(Date repayDate) {
        this.repayDate = repayDate;
    }

    public Integer getPayType() {
        return payType;
    }

    public void setPayType(Integer payType) {
        this.payType = payType;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getNextStepUserId() {
        return nextStepUserId;
    }

    public void setNextStepUserId(String nextStepUserId) {
        this.nextStepUserId = nextStepUserId;
    }

    public String getCreateName() {
        return createName;
    }

    public void setCreateName(String createName) {
        this.createName = createName;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getValidStatus() {
        return validStatus;
    }

    public void setValidStatus(Integer validStatus) {
        this.validStatus = validStatus;
    }

    public enum PayTypeEnum {

        CASH(1, "现金"),
        TRANSFER_ACCOUNTS(2, "转账");

        private int value;
        private String label;

        private PayTypeEnum(int value, String label) {
            this.value = value;
            this.label = label;
        }

        public static String valueOf(Integer value) {
            if (value == null) {
                return null;
            }
            for (PayTypeEnum loop : PayTypeEnum.values()) {
                if (value == loop.getValue()) {
                    return loop.getLabel();
                }
            }
            return null;
        }


        public int getValue() {
            return value;
        }

        public String getLabel() {
            return label;
        }

    }

    public enum DebitNoteStatusEnum {

        UNISSUED(1, "待借支"),
        ISSUED(2, "已借支");

        private int value;
        private String label;

        private DebitNoteStatusEnum(int value, String label) {
            this.value = value;
            this.label = label;
        }

        public static String valueOf(Integer value) {
            if (value == null) {
                return null;
            }
            for (DebitNoteStatusEnum loop : DebitNoteStatusEnum.values()) {
                if (value == loop.getValue()) {
                    return loop.getLabel();
                }
            }
            return null;
        }


        public int getValue() {
            return value;
        }

        public String getLabel() {
            return label;
        }

    }
}